package com.xdf.imoocdatav.service;

import com.xdf.imoocdatav.dao.cloud.DatavOrderMapper;
import com.xdf.imoocdatav.model.DatavOrder;
import com.xdf.imoocdatav.utils.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DatavOrderServiceImpl implements DatavOrderService {

    @Autowired
    private DatavOrderMapper dao;

    /**
     * 表 datav_order 中的字段 orderTrend 中保存了以英文逗号间隔
     * 的数字构成的字符串，在本方法中转换为数组后返回给前端
     * @return
     */
    @Override
    public List<DatavOrder> selectAll() {
        List<DatavOrder> list = dao.selectAll();
        if( list.size()<=0 )
            throw new BusinessException("没有订单信息数据！");

        for(int i =0;i<list.size();i++){
            String tmp = list.get(i).getOrderTrend();
            if( tmp != null && !"".equals(tmp) && tmp.length()>0 ){
                String[] arr = tmp.split(",");
                list.get(i).setOrderTrends(arr);
            }
        }
        return list;
    }
}
